package com.fs.leetcode.array;

import java.util.Arrays;

/**
 * @author shuai.fang
 * @date：2018-02-05
 * @description：
 * Given numRows, generate the first numRows of Pascal's triangle.

For example, given numRows = 5, Return

[

[1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]
 */
public class PascalTriangle {

	public static void main(String[] args) {
		int[][] pascalTriangle = pascalTriangle(7);
		pascalTriangle(pascalTriangle[4], 5);
	}

	public static int[][] pascalTriangle(int num) {
		int[][] pascalTriangle = new int[num][num];
		for (int i = 0; i < num; i++) {
			for (int j = 0; j <= i; j++) {
				if (j == 0 || j == i) {
					pascalTriangle[i][j] = 1;
				} else {
					pascalTriangle[i][j] = pascalTriangle[i - 1][j - 1] + pascalTriangle[i - 1][j];
				}
			}
			System.out.println(Arrays.toString(pascalTriangle[i]));
		}
		return pascalTriangle;
	}

	public static int[] pascalTriangle(int[] pascalTriangle, int length) {
		int[] newPascalTriangle = new int[pascalTriangle.length + 1];
		newPascalTriangle[0] = 1;
		newPascalTriangle[length] = 1;
		for (int i = 1; i < length; i++) {
			newPascalTriangle[i] = pascalTriangle[i - 1] + pascalTriangle[i];
		}
		System.out.println(Arrays.toString(newPascalTriangle));
		return newPascalTriangle;
	}


}
